package com.corgi.base.handler;

import com.corgi.base.constant.CommonConstant;
import com.corgi.base.toolkit.ResultUtil;
import com.corgi.repeat.annotation.Repeat;
import com.corgi.repeat.handler.CurrentRepeatAspectHandler;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.stereotype.Component;

/**
 * @title: RepeatAspectHandler
 * @description:
 * @author: dengmiao
 * @create: 2019-11-19 11:59
 **/
@Component
@Slf4j
public class RepeatAspectHandler implements CurrentRepeatAspectHandler {

    @Override
    public Object around(ProceedingJoinPoint pjp, Repeat repeat) throws Throwable {
        CommonConstant.HttpState httpState = CommonConstant.HttpState.REPEAT_SUBMIT_OPERATION;
        log.warn("接口幂等限制, {}, {}", repeat, httpState);
        return new ResultUtil<>().setErrorMsg(httpState.getValue(), httpState.getReasonPhrase());
    }
}
